package com.iflytek.autofly.setting.biz.base;

import android.app.ProgressDialog;
import android.content.Context;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

/**
 * <b>Description: </b>自定义的adapter基类<br/>
 * <b>Change History:</b><br/>
 * <table border="1">
 * <tr>
 * <td><b>user</b></td>
 * <td><b>date</b></td>
 * <td><b>time</b></td>
 * <td><b>reason</b></td>
 * </tr>
 * <tr>
 * <td>yutian2@iflytek.com</td>
 * <td>2015年5月26日</td>
 * <td>上午10:09:18</td>
 * <td>创建此文件</td>
 * </tr>
 * </table>
 *
 * @author JunLuan@iflytek.com
 */
public abstract class MyBaseAdapter extends BaseAdapter {
    protected List mItems;
    protected Context mContext;
    protected ListView mListView;
    // 常用进度条
    protected ProgressDialog mDialog;

    public MyBaseAdapter() {
        mItems = new ArrayList();
    }

    @Override
    public int getCount() {
        return mItems.size();
    }

    @Override
    public Object getItem(int position) {
        return mItems.get(position);
    }

    /**
     * 添加集合
     *
     * @param items
     * @Description
     * @author
     * @version 1.0 2012-7-10
     */
    public void addItems(List items) {
        this.mItems.addAll(items);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    /**
     * 获取集合
     *
     * @return List
     * @Description
     * @author 钱新才
     * @version 1.0 2012-7-10
     */
    public List getItems() {
        return mItems;
    }

    /**
     * 覆盖填充
     *
     * @param items
     * @Description
     * @author
     * @version 1.0 2012-7-10
     */
    public void setItems(List items) {
        this.mItems = items;
    }

    /**
     * changeData()
     *
     * @param null
     * @description 当数据发送改变时，调用此方法，更新界面
     * @Exception 异常对象
     * @author Mr Cheng
     * @date 2012-7-23
     */
    public void changeData(List items) {
        if (items != null) {
            this.mItems = items;
            this.notifyDataSetChanged();
        }
    }

    /**
     * @Title: clearList
     * @Description:
     * @author wzx
     * @date 2012-11-6
     */
    public void clearList() {
        if (mItems != null) {
            mItems.clear();
        }
    }

    /**
     * 长提示
     *
     * @param resId 文本资源ID
     * @Description
     * @author 钱新才
     * @version
     */
    protected void toastLong(int resId) {
        Toast.makeText(mContext, mContext.getResources().getString(resId), Toast.LENGTH_LONG).show();
    }

    /**
     * 创建进度条
     *
     * @param mContext
     * @param resId
     * @return ProgressDialog
     * @Description
     * @author 钱新才
     * @version 1.0 2012-7-19
     */
    public ProgressDialog createProgress(int resId) {
        ProgressDialog dialog = new ProgressDialog(mContext);
        dialog.setMessage(mContext.getResources().getString(resId));
        dialog.setIndeterminate(false);
        dialog.setCancelable(true);
        return dialog;
    }

    /**
     * 长提示
     *
     * @param context
     * @param msg
     * @Description
     * @author 钱新才
     * @version 1.0 2012-7-18
     */
    protected void toastLong(String msg) {
        Toast.makeText(mContext, msg, Toast.LENGTH_LONG).show();
    }

}
